const path = require('path');

const Multer = require('koa-multer');

const {AVATAR_PATH} = require('../constants/file-path');

const randomNum = Math.floor((Math.random() * 100000) + 1);

const storage = Multer.diskStorage({
  destination: (req, file, cb) => {
    cb(null, AVATAR_PATH);
  },
  filename: (req, file, cb) => {
    cb(null, `${Date.now()}${randomNum}${path.extname(file.originalname)}`);
  }
})

const avatarUpload = Multer ({
  storage
})


const avatarHandler = avatarUpload.single('avatar');

module.exports = {
  avatarHandler
}